# Shift table by x elements

inputs = []
inputs += [[1]]
inputs += [[1, 2]]
inputs += [[1, 2, 3]]
inputs += [[1, 2, 3, 4]]
inputs += [[1, 2, 3, 4, 5]]
inputs += [[1, 2, 3, 4, 5, 6]]
inputs += [[1, 2, 3, 4, 5, 6, 7]]
inputs += [[1, 2, 3, 4, 5, 6, 7, 8]]
inputs += [[1, 2, 3, 4, 5, 6, 7, 8, 9]]
inputs += [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]

def swap_element(table, i, j):
	tmp = table[i]
	table[i] = table[j]
	table[j] = tmp

def shift_recursive(table, x, size):
	if size <= 1 or x % size == 0:
		# Table's size is less than 2, or we shift by 0 elements - nothing to do
		return
	elif size >= 2*x:
		for i in xrange(0, x):
			swap_element(table, i, size - x + i)
		shift_recursive(table, x, size - x)
	else:
		for i in xrange(0, size - x):
			swap_element(table, 2*x - size + i, x + i)
		shift_recursive(table, 2*x - size, x)

def shift(table, x):
	shift_recursive(table, x % len(table), len(table))
	return table

for input in inputs:
	for x in xrange(0, len(input) + 1):
		print "Shifting by", x, input, "->", shift(list(input), x)